home *** CD-ROM | disk | FTP | other *** search
/ Internet Info 1994 March / Internet Info CD-ROM (Walnut Creek) (March 1994).iso / networking / terms / kermit / b / ckudir.doc < prev    next >
Encoding:
Internet Message Format  |  1992-11-22  |  9.4 KB

  1. Date: Fri, 22 Jun 90 20:15:30 EDT
  2. From: Frank da Cruz <fdc@watsun.cc.columbia.edu>
  3. Subject: dirent.h vs dir.h
  4.  
  5. I'm attacking C-Kermit's problems with long filenames and wildcard expansion
  6. now.  These problems have been most noticable on HP-UX, MIPS, RTU, and other
  7. System-V based systems.  Berkeley-based systems seem to have no problem.
  8.  
  9. I think I'm beginning to understand what's going on.  My theory is that most
  10. of the System-V based systems on which Kermit's wildcard expansion is broken
  11. are using <sys/dir.h> with open(), read(), and close() to access the
  12. directory, which up till now has been what you got if UXIII was defined.
  13.  
  14. But according to SVID (R2 and R3), not to mention POSIX, we should be using
  15. <dirent.h> with opendir(), readdir(), and closedir().  Does anybody know when
  16. <dirent.h> entered the picture?  Was it a Sys V R2 invention?  Was it Sys V R0
  17. (was there such a thing?  -- I mean, is <dirent.h> one of the things that
  18. distinguishes System III from System V?)  Is <dirent.h> available on Xenix
  19. systems?
  20.  
  21. I've looked on vanilla Berkeley 4.2 and 4.3 systems and can't find <dirent.h>,
  22. so I'm assuming it's an AT&Tism and we needn't bother about in BSD-based
  23. Kermit implementations.  Among the hybrids, <dirent.h> is available in SUNOS
  24. 4.x and AIX/370, but not Encore UMAX 4.3, not Ultrix 2.0, ... so we take our
  25. chances.
  26.  
  27. There also seem to be at least three examples of AT&T Unixes with BSD file
  28. systems, which do NOT use <dirent.h>: HP-UX (6.2 and later?), Silicon Graphics
  29. Iris, and Masscomp RTU.  These will need a special notation in the makefile,
  30. if indeed <dirent.h> is truly not available.
  31.  
  32. I think I have developed a relatively clean way to handle all these variations
  33. in the makefile.  The main rule is: if your system has <dirent.h>, use it.  So
  34. I'm mostly interested now in finding out which systems can be expected to
  35. supply /usr/include/dirent.h.
  36.  
  37. Thanks!  - Frank
  38.  
  39. ------------------------------
  40.  
  41. Date: Fri, 22 Jun 90 19:59:40 PDT
  42. From: andy@csvax.caltech.edu (Andy Fyfe)
  43. To: fdc@watsun.cc.columbia.edu
  44. Subject: Re:  dirent.h vs dir.h
  45.  
  46. The UnixPC comes with no directory-reading routines.  I have the dirent
  47. library (from Doug Gwyn) installed.  Here's the NOTES file from the
  48. distribution -- it has some background on where it came from.
  49.  
  50. --andy
  51.  
  52.  
  53. NOTES FOR NEARLY-POSIX-COMPATIBLE C LIBRARY DIRECTORY-ACCESS ROUTINES
  54.  
  55.  
  56. Older UNIX C libraries lacked support for reading directories, so historically
  57. programs had knowledge of UNIX directory structure hard-coded into them.  When
  58. Berkeley changed the format of directories for 4.2BSD, it became necessary to
  59. change programs to work with the new structure.  Fortunately, Berkeley designed
  60. a small set of directory access routines to encapsulate knowledge of the new
  61. directory format so that user programs could deal with directory entries as an
  62. abstract data type.  (Unfortunately, they didn't get it quite right.)  The
  63. interface to these routines was nearly independent of the particular
  64. implementation of directories on any given UNIX system; this has become a
  65. particularly important requirement with the advent of heterogeneous network
  66. filesystems such as NFS.
  67.  
  68. It has consequently become possible to write portable applications that search
  69. directories by restricting all directory access to use these new interface
  70. routines.  The sources supplied here are a total rewrite of Berkeley's code,
  71. incorporating ideas from a variety of sources and conforming as closely to
  72. published standards as possible, and are in the PUBLIC DOMAIN to encourage
  73. their widespread adoption.  They support four methods of access to system
  74. directories: the original UNIX filesystem via read(), the 4.2BSD filesystem via
  75. read(), NFS and native filesystems via getdirentries(), and SVR3 getdents().
  76. The other three types are accomplished by appropriate emulation of the SVR3
  77. getdents() system call, which attains portability at the cost of slightly more
  78. data movement than absolutely necessary for some systems.  These routines
  79. should be added to the standard C library on all UNIX systems, and all existing
  80. and future applications should be changed to use this interface.  Once this is
  81. done, there should be no portability problems due to differences in underlying
  82. directory structures among UNIX systems.  (When porting your applications to
  83. other UNIX systems, you can always carry this package around with you.)
  84.  
  85. An additional benefit of these routines is that they buffer directory input,
  86. which provides improved access speed over raw read()s of one entry at a time.
  87.  
  88. One annoying compatibility problem has arisen along the way, namely that the
  89. original Berkeley interface used the same name, struct direct, for the new data
  90. structure as had been used for the original UNIX filesystem directory record
  91. structure.  This name was changed by the IEEE 1003.1 (POSIX) Working Group to
  92. "struct dirent" and was picked up for SVR3 under the new name; it is also the
  93. name used in this portable package.  I believe it is necessary to bite the
  94. bullet and adopt the new non-conflicting name.  Code using a 4.2BSD-compatible
  95. package needs to be slightly revised to work with this new package, as follows:
  96.     Change
  97.         #include <ndir.h>    /* Ninth Edition UNIX */
  98.     or
  99.         #include <sys/dir.h>    /* 4.2BSD */
  100.     or
  101.         #include <dir.h>    /* BRL System V emulation */
  102.     to
  103.         #include <sys/types.h>    /* if not already #included */
  104.         #include <dirent.h>
  105.  
  106.     Change
  107.         struct direct
  108.     to
  109.         struct dirent
  110.  
  111.     Change
  112.         (anything)->d_namlen
  113.     to
  114.         strlen( (anything)->d_name )
  115.  
  116. There is a minor compatibility problem in that the closedir() function was
  117. originally defined to have type void, but IEEE 1003.1 changed this to type int,
  118. which is what this implementation supports (even though I disagree with the
  119. change).  However, the difference does not affect most applications.
  120.  
  121. Another minor problem is that IEEE 1003.1 defined the d_name member of a struct
  122. dirent to be an array of maximum length; this does not permit use of compact
  123. variable-length entries directly from a directory block buffer.  This part of
  124. the specification is incompatible with efficient use of the getdents() system
  125. call, and I have therefore chosen to follow the SVID specification instead of
  126. IEEE 1003.1 (which I hope is changed for the final-use standard).  This
  127. deviation should have little or no impact on sensibly-coded applications, since
  128. the relevant d_name length is that given by strlen(), not the declared array
  129. size.
  130.  
  131. Error handling is not completely satisfactory, due to the variety of possible
  132. failure modes in a general setting.  For example, the rewinddir() function
  133. might fail, but there is no good way to indicate this.  I have tried to
  134. follow the specifications in IEEE 1003.1 and the SVID as closely as possible,
  135. but there are minor deviations in this regard.  Applications should not rely
  136. too heavily on exact failure mode semantics.
  137.  
  138. Please do not change the new standard interface in any way, as that would
  139. defeat the major purpose of this package!  (It's okay to alter the internal
  140. implementation if you really have to, although I tried to make this unnecessary
  141. for the vast majority of UNIX variants.)
  142.  
  143. Installation instructions can be found in the file named INSTALL.
  144.  
  145. This implementation is provided by:
  146.  
  147.     Douglas A. Gwyn
  148.     U.S. Army Ballistic Research Laboratory
  149.     SLCBR-VL-V
  150.     Aberdeen Proving Ground, MD 21005-5066
  151.  
  152.     (301)278-6647
  153.  
  154.     Gwyn@BRL.MIL or seismo!brl!gwyn
  155.  
  156. This is UNSUPPORTED, use-at-your-own-risk, free software in the public domain.
  157. However, I would appreciate hearing of any actual bugs you find in this
  158. implementation and/or any improvements you come up with.
  159.  
  160. ------------------------------
  161.  
  162. Date: Sat, 23 Jun 90 00:01:58 -0400
  163. From: djm@eng.umd.edu (David J. MacKenzie)
  164. To: fdc@watsun.cc.columbia.edu
  165. Subject: dirent.h vs dir.h
  166.  
  167. > But according to SVID (R2 and R3), not to mention POSIX, we should be using
  168. > <dirent.h> with opendir(), readdir(), and closedir().  Does anybody know when
  169. > <dirent.h> entered the picture?
  170.  
  171. There are several variations on the opendir et al. directory library:
  172.  
  173. The first portable directory access library was introduced in 4.2BSD,
  174. along with the BSD Fast Filesystem (according to The Design and
  175. Implementation of the 4.3BSD Unix Operating System).  The same library
  176. is used in 4.3BSD.  It uses `struct direct' and <sys/dir.h>.
  177.  
  178. SVR2 (I believe) introduced to System V an early version of Doug
  179. Gwynn's public domain reimplementation of the BSD library for the old
  180. (14 character filename) filesystem.  It uses `struct direct' and <ndir.h>.
  181.  
  182. SVR3 renamed `struct direct' to `struct dirent' to fix a conflict with
  183. a different `struct direct' in the old 14-character filesystem's
  184. <sys/dir.h> header file and changed the header file to <dirent.h>.  It
  185. also removed the d_namlen structure member.  I think these changes
  186. were because they were proposed by POSIX (and eventually approved).
  187. Doug Gwynn later revised his public domain library to conform to the
  188. POSIX/SVR3 scheme.
  189.  
  190. Early Xenix systems have `struct direct' and <sys/ndir.h> (I think
  191. Xenix is unique in the placement of the ndir.h file in
  192. /usr/include/sys), accessed by linking with -lx.  More recent Xenix
  193. systems also have the SVR3/POSIX `struct dirent' and <dirent.h>,
  194. accessed by linking with -ldir.  I think some intermediate Xenix
  195. systems have both libraries but have a buggy version of the <dirent.h>
  196. one.  On Xenix, only the <dirent.h> library can access network drives.
  197.  
  198. SunOS started out as BSD with <sys/dir.h> but in later versions added
  199. the POSIX/SVR3 <dirent.h> as well.  Other merged BSD/SysV systems have
  200. various combinations of available headers.
  201.  
  202. New systems, like 4.4BSD and GNU, will have <dirent.h>.
  203.  
  204.